<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户" prop="userNick">
        <el-input v-model="queryParams.userNick" placeholder="请输入用户" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="monthwsList" @selection-change="handleSelectionChange">
      <el-table-column label="用户" align="center" prop="userNick" fixed />
      <el-table-column label="日期" align="center" prop="ofcmpayMonth">
        <template slot-scope="scope">
          <span>{{ scope.row.wsmpayYear + "-" + scope.row.wsmpayMonth }}</span>
        </template>
      </el-table-column>
      <el-table-column label="底薪" align="center" prop="basicSalary" />
      <el-table-column label="扣款金额" align="center" prop="dmAmount" />
      <el-table-column label="考勤补贴" align="center" prop="workAllowance" />
      <el-table-column label="其他补助" align="center" prop="otherSubsidy" />
      <el-table-column label="绩效比例" align="center" prop="personalPerformance" />
      <el-table-column label="计件工资" align="center" prop="basicSalary" />
      <el-table-column label="工龄工资" align="center" prop="ageAllpay" />
      <el-table-column label="餐补" align="center" prop="mealAllowance" />
      <el-table-column label="高温补贴" align="center" prop="highTemperature" />
      <el-table-column label="早班次数" align="center" prop="earlyNum" />
      <el-table-column label="早班补助" align="center" prop="earlyShift" />
      <el-table-column label="晚班次数" align="center" prop="nightNum" />
      <el-table-column label="晚班补助" align="center" prop="nightShift" />
      <el-table-column label="加班补贴" align="center" prop="overtimeAllallowance" />
      <el-table-column label="应发工资" align="center" prop="wagePayable" />
      <el-table-column label="公积金" align="center" prop="providentFund" />
      <el-table-column label="社保" align="center" prop="socialSecurity" />
      <el-table-column label="代扣税" align="center" prop="taxDeduction" />
      <el-table-column label="每月实发" align="center" prop="netSalary" />
      <el-table-column label="满勤天数" align="center" prop="fullDay" />
      <el-table-column label="出勤天数" align="center" prop="attendanceDay" />
      <el-table-column label="缺勤天数" align="center" prop="absenceDay" />
      <el-table-column label="操作" fixed="right" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['sl:monthws:edit']">修改</el-button>
          <!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sl:monthws:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改车间工资对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="用户" prop="userNick">
              {{form.userNick}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="日期" prop="wsmpayYear">
              {{form.wsmpayYear + '-' + form.wsmpayMonth}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="工资" prop="basicSalary">
              {{form.basicSalary}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="扣款" prop="dmAmount">
              {{form.dmAmount}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="考勤补贴" prop="workAllowance">
              <el-input v-model="form.workAllowance" class="def-input-number" type="number" placeholder="请输入考勤补贴" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="绩效比例" prop="personalPerformance">
              {{form.personalPerformance}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="高温补贴" prop="highTemperature">
              <el-input v-model="form.highTemperature" class="def-input-number" type="number" placeholder="请输入高温补贴" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="加班补贴" prop="overtimeAllallowance">
              <el-input v-model="form.overtimeAllallowance" class="def-input-number" type="number"
                placeholder="请输入加班补助" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="工龄" prop="workingAge">
              <el-input v-model="form.workingAge" class="def-input-number" type="number" placeholder="请输入工龄" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="工龄工资基础" prop="ageBase">
              <el-input v-model="form.ageBase" class="def-input-number" type="number" placeholder="请输入工龄工资基础" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="工龄工资" prop="ageAllpay">
              {{form.ageAllpay}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="其他补贴" prop="otherSubsidy">
              <el-input v-model="form.otherSubsidy" class="def-input-number" type="number" placeholder="请输入其他补贴" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="6">
            <el-form-item label="餐补基数" prop="mealBase">
              <el-input v-model="form.mealBase" class="def-input-number" type="number" placeholder="请输入餐补基数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="餐补" prop="mealAllowance">
              {{form.mealAllowance}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="早班次数" prop="earlyNum">
              <el-input v-model="form.earlyNum" @change="handleEarly" class="def-input-number" type="number"
                placeholder="请输入早班次数" />
            </el-form-item>

          </el-col>
          <el-col :span="6">
            <el-form-item label="早班补助基数" prop="earlyBase">
              <el-input v-model="form.earlyBase" class="def-input-number" type="number" placeholder="请输入早班补助基数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="早班补助" prop="earlyShift">
              {{form.earlyShift}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="晚班次数" prop="nightNum">
              <el-input v-model="form.nightNum" @change="handleNight" class="def-input-number" type="number"
                placeholder="请输入晚班次数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="晚班补助基数" prop="nightBase">
              <el-input v-model="form.nightBase" class="def-input-number" type="number" placeholder="请输入晚班补助基数" />
            </el-form-item>
          </el-col>
            <el-col :span="6">
              <el-form-item label="晚班补助" prop="nightShift">
                {{form.nightShift}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="公积金" prop="providentFund">
                {{form.providentFund}}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="社保" prop="socialSecurity">
                {{form.socialSecurity}}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="代扣税" prop="taxDeduction">
                {{form.taxDeduction}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="应发工资" prop="wagePayable">
                {{form.wagePayable}}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="实发" prop="netSalary">
                {{form.netSalary}}
              </el-form-item>
            </el-col>
           
          </el-row>

          <el-row>
            <el-col :span="6">
              <el-form-item label="满勤天数" prop="fullDay">
                {{form.fullDay}}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="出勤天数" prop="attendanceDay">
                {{form.attendanceDay}}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="缺勤天数" prop="absenceDay">
                {{form.absenceDay}}
              </el-form-item>
            </el-col>

            <el-col :span="6">

            </el-col>
          </el-row>
          <div v-if="form.slWsperformance!=null">
            <el-divider content-position="center">绩效信息</el-divider>
            <el-row>
              <el-col :span="6">
                <el-form-item label="绩效天数">
                  {{form.slWsperformance.performanceDay}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="缺勤天数">
                  {{form.slWsperformance.absenceDay}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="绩效基数">
                  {{form.slWsperformance.performanceBase}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="扣发绩效">
                  {{form.slWsperformance.performanceDeduction}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="工作绩效">
                  {{form.slWsperformance.deduction}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="剩余绩效">
                  {{form.slWsperformance.performanceResidue}}
                </el-form-item>
              </el-col>
            </el-row>
          </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">更 新</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listMonthws,
    getMonthws,
    delMonthws,
    addMonthws,
    updateMonthws
  } from "@/api/sl/monthws";

  export default {
    name: "Monthws",
    data() {
      let watermarkContentVaild = (rule, value, callback) => {
        if (value == null || value === "") {
          callback(new Error("不能为空"))
        } else {
          let length = value.length
          if (length > 7) {
            callback(new Error("输入不能超过7位"))
          } else {
            callback();
          }
        }
      }

      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 车间工资表格数据
        monthwsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: null,
          userNick: null,
          moduleId: null,
          workshopId: null,
          gprocessId: null,
          deptId: null,
          wsmpayYear: null,
          wsmpayMonth: null,
          levelId: null,
          ssmId: null,
          isHistory: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          overtimeAllallowance: [{
            validator: watermarkContentVaild,
            trigger: 'blur'
          }],
          earlyNum: [{
            validator: watermarkContentVaild,
            trigger: 'blur'
          }],
          nightNum: [{
            validator: watermarkContentVaild,
            trigger: 'blur'
          }],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询车间工资列表 */
      getList() {
        this.loading = true;
        this.queryParams.isHistory = "1";
        listMonthws(this.queryParams).then(response => {
          this.monthwsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          wsmpayId: null,
          userName: null,
          userNick: null,
          moduleId: null,
          workshopId: null,
          gprocessId: null,
          deptId: null,
          wsmpayYear: null,
          wsmpayMonth: null,
          wsmpayStart: null,
          wsmpayEnd: null,
          basicSalary: null,
          levelPay: null,
          postPay: null,
          gradePay: null,
          educationPay: null,
          workAllowance: null,
          personalPerformance: null,
          deptPerformance: null,
          fixedSalary: null,
          totalReward: null,
          workingAge: null,
          ageBase: null,
          ageAllpay: null,
          agePay: null,
          mealAllowance: null,
          mealBase: null,
          highTemperature: null,
          earlyNum: null,
          earlyBase: null,
          earlyShift: null,
          nightNum: null,
          nightBase: null,
          nightShift: null,
          overtimeAllallowance: null,
          overtimeAllowance: null,
          wagePayable: null,
          providentFund: null,
          socialSecurity: null,
          taxDeduction: null,
          netSalary: null,
          fullDay: null,
          attendanceDay: null,
          absenceDay: null,
          attendancePay: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          levelId: null,
          ssmId: null,
          isHistory: null,
          dmAmount: null,
          otherSubsidy: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.wsmpayId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加车间工资";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const wsmpayId = row.wsmpayId || this.ids
        getMonthws(wsmpayId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改车间工资";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.wsmpayId != null) {
              updateMonthws(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addMonthws(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const wsmpayIds = row.wsmpayId || this.ids;
        this.$modal.confirm('是否确认删除车间工资编号为"' + wsmpayIds + '"的数据项？').then(function() {
          return delMonthws(wsmpayIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('sl/monthws/export', {
          ...this.queryParams
        }, `monthws_${new Date().getTime()}.xlsx`)
      },
      handleEarly() {
        this.form.earlyShift = (this.form.earlyBase * this.form.earlyNum).toFixed(2);
      },
      handleNight() {
        this.form.nightShift = (this.form.nightBase * this.form.nightNum).toFixed(2);
      }
    }
  };
</script>
<style>
  .el-table .el-table__body-wrapper::-webkit-scrollbar {
    height: 10px;
  }
</style>
